package jpal.io;

import static com.google.common.base.Preconditions.checkNotNull;
import static jpal.io.FileWalker.VisitResult.CONTINUE;

import java.io.File;
import java.io.IOException;

/**
 * A basic implementation of {@code FileWalker} which visits all files and
 * directories, rethrows any {@code IOException}s, and returns a {@code null}
 * result.
 * <p>
 * Methods in this class may be overridden to customize the implementation.
 * 
 * @param <R>
 *            the type of result returned by this {@code FileWalker}
 * @author Zhenya Leonov
 */
public class SimpleFileWalker<R> implements FileWalker<R> {

	@Override
	public VisitResult preVisitDirectory(File dir) {
		checkNotNull(dir);
		return CONTINUE;
	}

	@Override
	public VisitResult postVisitDirectory(File dir) {
		checkNotNull(dir);
		return CONTINUE;
	}

	@Override
	public VisitResult visitFile(File file) throws IOException {
		checkNotNull(file);
		return CONTINUE;
	}

	@Override
	public VisitResult visitFileFailed(File file, IOException ex)
			throws IOException {
		checkNotNull(file);
		checkNotNull(ex);
		throw ex;
	}

	@Override
	public R getResult() {
		return null;
	}

}
